package com.qipay.baas.mapper;

import com.qipay.baas.model.SpConfig;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface SpConfigMapper {
    @Delete({
        "delete from sp_config",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into sp_config (sp_id, `key`, ",
        "val)",
        "values (#{spId,jdbcType=BIGINT}, #{key,jdbcType=VARCHAR}, ",
        "#{val,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(SpConfig record);

    @InsertProvider(type=SpConfigSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(SpConfig record);

    @Select({
        "select",
        "id, sp_id, `key`, val",
        "from sp_config",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="sp_id", property="spId", jdbcType=JdbcType.BIGINT),
        @Result(column="key", property="key", jdbcType=JdbcType.VARCHAR),
        @Result(column="val", property="val", jdbcType=JdbcType.VARCHAR)
    })
    SpConfig selectByPrimaryKey(Long id);

    @UpdateProvider(type=SpConfigSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SpConfig record);

    @Update({
        "update sp_config",
        "set sp_id = #{spId,jdbcType=BIGINT},",
          "`key` = #{key,jdbcType=VARCHAR},",
          "val = #{val,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(SpConfig record);
}